public class Test {
    public static void main(String[] args) throws InterruptedException {
        Object o1 = new Object();
        Object o2 = new Object();
        Object o3 = new Object();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized(o1){
                    try {
                        System.out.print("A");
                        o1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });//
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized(o2){
                    o1.notify();
                    try {
                        System.out.print("B");
                        o2.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread t3 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized(o2){
                    o2.notify();
                    System.out.println("C");
                }
            }
        });
        t1.start();
        Thread.sleep(500);
        t2.start();
        Thread.sleep(500);
        t3.start();
    }
}
